package com.dailyblue.java.thread.作业;

import lombok.SneakyThrows;

import java.util.concurrent.FutureTask;

public class App {

    private static void a() {
        DemoA a = new DemoA("线程1");
        a.start();
    }

    private static void b() {
        /*DemoB2 b2 = new DemoB2();
        new Thread(b2).start();*/
    }

    private static void c() {
        DemoA a = new DemoA("线程1");
        a.start();
        DemoB2 b2 = new DemoB2(a);
        new Thread(b2).start();
    }

    @SneakyThrows
    private static void d() {
        DemoC c = new DemoC();
        int count = c.size();
        System.out.println(c);
        for (int i = 0; i < count; i++) {
            DemoC2 c2 = new DemoC2(c.get(i));
            FutureTask<Integer> task = new FutureTask<>(c2);
            Thread t = new Thread(task);
            t.start();
            System.out.println(t.getName() + "计算的结果是：" + task.get());
        }
    }

    private static void e() {
        DemoD d = new DemoD();
        for (int i = 0; i < 4; i++) {
            DemoD2 d2 = new DemoD2(d);
            Thread t = new Thread(d2);
            t.start();
        }
    }

    public static void main(String[] args) {
        e();
    }
}
